<template>
  <el-form ref="form" :model="form" :rules="rules" label-width="80px" size="small" :disabled="clickType == 'view'">
    <!--名称-->
    <el-form-item :label="$t('largeModel.name')+':'" prop="name" >
      <el-input
        maxlength="30"
        v-model="form.name"
        show-word-limit
        :placeholder="$t('largeModel.nameTips')"
      >
      </el-input>
    </el-form-item>
    <!--功能-->
    <el-form-item :label="$t('largeModel.function')+':'" prop="function" >
<!--      <el-select v-model="form.function">-->
<!--        <el-option-->
<!--          v-for="item in funList"-->
<!--          :key="item.value"-->
<!--          :label="item.label"-->
<!--          :value="item.value"-->
<!--        >-->
<!--        </el-option>-->
<!--      </el-select>-->

      <el-select v-model="form.function" filterable @change="changeType">
        <el-option-group
          v-for="group in funList"
          :key="group.label"
          :label="group.label">
          <el-option
            v-for="item in group.children"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-option-group>
      </el-select>

    </el-form-item>
    <!--提示词-->
    <el-form-item :label="$t('largeModel.tipWord')+':'" prop="tipWord">
      <el-input
        maxlength="300"
        v-model="form.tipWord"
        show-word-limit
        type="textarea"
        :rows="4"
        :placeholder="tips"
        ref="tipWordInput"
      >
      </el-input>
      <div class="insert-value">
        <div style="display: flex;align-items: end">
          <!-- 变量由${}表示 -->
          <span class="insert-tip" style="margin-right: 5px;color:#9597a0">{{$t('largeModel.valueTips')}}</span>
          <el-link type="primary" :underline="false" @click="handlerInsert" :disabled="clickType == 'view'">{{$t('largeModel.insertVariable')}}</el-link> <!--插入变量-->
        </div>
        <div>
          <!--当前生成模式-->
          <span>{{$t('largeModel.currentGenerationMode')}}:</span>
          <span>{{$t('largeModel.commonMode')}}</span>
        </div>
      </div>
    </el-form-item>
  </el-form>
</template>

<script>
export default {

  computed:{
    // tips(){
    //   console.log('22222',this.form.function)
    //   if (this.form.function == '9'){
    //     this.form.tipWord = '请对${content}进行回复'
    //     return '请对${content}进行回复'
    //   }else if (this.form.function == '2'){
    //     this.form.tipWord = '请根据${content}生成答案'
    //     return '请根据${content}生成答案'
    //   }else if (this.form.function == '6'){
    //     this.form.tipWord = '请对${content}进行话术优化'
    //     return '请对${content}进行话术优化'
    //   }else if (this.form.function == '11'){
    //     this.form.tipWord = '请对${content}进行改写优化'
    //     return '请对${content}进行改写优化'
    //   }else if (this.form.function == '10'){
    //     this.form.tipWord = '请扩写${content}使其表达清晰完整,用于提升意图匹配'
    //     return '请扩写${content}使其表达清晰完整,用于提升意图匹配'
    //   }else if (this.form.function == '1'){
    //     this.form.tipWord = '请根据${content}生成相似问'
    //     return '请根据${content}生成相似问'
    //   }else if (this.form.function == '13'){
    //     this.form.tipWord = '请根据${content}进行搜索'
    //     return '请根据${content}进行搜索'
    //   }else if (this.form.function == '14'){
    //     this.form.tipWord = '请根据${content}进行转写'
    //     return '请根据${content}进行转写'
    //   }else if (this.form.function == '15'){
    //     this.form.tipWord = '请根据${content}进行小结'
    //     return '请根据${content}进行小结'
    //   }else if (this.form.function == '16'){
    //     this.form.tipWord = '请根据${content}生成用户画像'
    //     return '请根据${content}生成用户画像'
    //   }else if (this.form.function == '17'){
    //     this.form.tipWord = '请根据${content}进行数据分析'
    //     return '请根据${content}进行数据分析'
    //   }
    // },
  },

  data(){
    return {
      funList:[
        {
          label:this.$t('largeModel.intelligentSessionEnhancement'),  //智能会话增强
          value:'1',
          children:[
            {
              label:this.$t('largeModel.robotFallBack'), //机器人兜底
              value:'9',
            },
            {
              label:this.$t('largeModel.userQuestionExpansion'), //用户问题改写
              value:'10',
            },
            {
              label:this.$t('largeModel.nodeSceneSpeechRewrite'), //节点情境话术改写
              value:'11',
            },
          ],
        },
        {
          label:this.$t('largeModel.knowledgeEnhancement'),  //知识增强
          value:'2',
          children:[
            {
              label:this.$t('largeModel.similarQuestionGeneration'), //相似问生成
              value:'1',
            },
            {
              label:this.$t('largeModel.answerGeneration'), //答案生成
              value:'2',
            },
            {
              label:this.$t('largeModel.speechNodeOptimization'), //话术节点优化
              value:'6',
            },
          ]
        },
        {
          label:this.$t('largeModel.agentAssistantEnhancement'),  //坐席辅助增强
          value:'3',
          children:[
            {
              label:this.$t('largeModel.agentIntelligentSearch'), //坐席智能搜索
              value:'13',
            },
            {
              label:this.$t('largeModel.agentIntelligentTranslation'), //坐席一键转写
              value:'14',
            },
            {
              label:this.$t('largeModel.agentIntelligentSummary'), //坐席智能小结
              value:'15',
            },
          ],
        },
        {
          label:this.$t('largeModel.dataAnalysisEnhancement'),  //数据分析增强
          value:'4',
          children:[
            {
              label:this.$t('largeModel.userPortraitLabel'), //用户画像标签
              value:'16',
            },
            {
              label:this.$t('largeModel.dataAnalysis'), //数据分析
              value:'17',
            },
          ],
        },
      ],
      form:{
        name:'',
        function:'9', //分类
        tipWord:'请对${content}进行回复',  //提示词
        isDefault:0,
        pattern:2, //现在默认为普通模式
        isUse:0, //默认都没使用
        id:'',
      },
      rules:{
        name:[
          { required: true, message: this.$t('largeModel.nameTips'), trigger: 'blur' },
        ],
        tipWord:[
          { required: true, message: this.$t('largeModel.tipWordTipsTwo'), trigger: 'blur' },
        ],
      },
    }
  },
  props:{
    cur:{
      type:Object,
      default:() => {
        return {}
      }
    },
    clickType:{
      type:String,
      default:() => {
        return ''
      }
    },
  },
  mounted(){
    if(this.cur.id){
      const Data = this.cur;
      console.log(Data,'Data')
      this.form={
        name:Data.name,
        function:Data.businessType ==''||Data.businessType=== null?'':Data.businessType?Data.businessType.toString():'',
        tipWord: Data.content,
        isDefault: Data.isDefault,
        id:Data.id,
        pattern:Data.pattern,
        isUse:Data.isUse
      };
    }else {
      // const insert = '${content}';
      // this.form.tipWord = `请根据${insert}生成答案`;
      this.$refs.tipWordInput.focus();
    }
  },
  methods:{
    //插入变量
    handlerInsert(){
      const insert = '${content}';
      this.form.tipWord = this.form.tipWord + insert;
      this.$refs.tipWordInput.focus();
    },

    changeType() {
      if (this.form.function == '9'){
        this.form.tipWord = '请对${content}进行回复'
        return '请对${content}进行回复'
      }else if (this.form.function == '2'){
        this.form.tipWord = '请根据${content}生成答案'
        return '请根据${content}生成答案'
      }else if (this.form.function == '6'){
        this.form.tipWord = '请对${content}进行话术优化'
        return '请对${content}进行话术优化'
      }else if (this.form.function == '11'){
        this.form.tipWord = '请对${content}进行改写优化'
        return '请对${content}进行改写优化'
      }else if (this.form.function == '10'){
        this.form.tipWord = '请扩写${content}使其表达清晰完整,用于提升意图匹配'
        return '请扩写${content}使其表达清晰完整,用于提升意图匹配'
      }else if (this.form.function == '1'){
        this.form.tipWord = '请根据${content}生成相似问'
        return '请根据${content}生成相似问'
      }else if (this.form.function == '13'){
        this.form.tipWord = '请根据${content}进行搜索'
        return '请根据${content}进行搜索'
      }else if (this.form.function == '14'){
        this.form.tipWord = '请根据${content}进行转写'
        return '请根据${content}进行转写'
      }else if (this.form.function == '15'){
        this.form.tipWord = '请根据${content}进行小结'
        return '请根据${content}进行小结'
      }else if (this.form.function == '16'){
        this.form.tipWord = '请根据${content}生成用户画像'
        return '请根据${content}生成用户画像'
      }else if (this.form.function == '17'){
        this.form.tipWord = '请根据${content}进行数据分析'
        return '请根据${content}进行数据分析'
      }
    }
  },
}
</script>

<style scoped lang="scss">
.insert-value{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
</style>
